package com.tshopping.controller;

import com.tshopping.bean.DataModel;
import com.tshopping.service.GoodsService;
import com.tshopping.service.ParameterService;
import com.tshopping.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @name: GoodsController
 * @description: 商品页面控制器
 * @author: Jackeys
 * @date: 2021-01-23 22:20
 */
@RestController
@RequestMapping("/GoodsController")
@CrossOrigin
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private ParameterService parameterService;

    @PostMapping(value = "/uploadGoodsPicture")
    /**
     * @description 处理用户上传商品照片
     * @Param: request
     * @Param: email
     * @Param: file
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-24 12:41
     */
    public ResponseData uploadGoodsPicture(HttpServletRequest request, String email, @RequestParam(value = "file", required = false) MultipartFile file){
        return goodsService.uploadGoodsPicture(request,email,file);
    }

    @PostMapping(value = "/addGoods")
    /**
     * @description 处理商家添加商品
     * @Param: dataModel
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-24 16:50
     */
    public ResponseData addGoods(@RequestBody DataModel dataModel){
        return goodsService.addGoods(dataModel);
    }

    @PostMapping(value = "/getGoodsList")
    /**
     * @description 处理用户获取商品集
     * @Param: store
     * @Param: user
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-25 09:39
     */
    public ResponseData getGoodsList(int store, int user, int currentPage){
        return goodsService.getGoods(store,user,currentPage);
    }

    @PostMapping(value = "/getGoods")
    /**
     * @description 处理用户获取商品
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-25 09:43
     */
    public ResponseData getGoods(int id){
        return goodsService.selectGoods(id);
    }

    @PostMapping(value = "/updateGoods")
    /**
     * @description 处理商家修改商品
     * @Param: dataModel
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-25 14:43
     */
    public ResponseData updateGoods(@RequestBody DataModel dataModel){
        return goodsService.updateGoods(dataModel);
    }

    @PostMapping(value = "/deleteGoods")
    /**
     * @description 处理用户删除商品
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-26 09:43
     */
    public ResponseData deleteGoods(int id){
        return goodsService.deleteGoods(id);
    }

    @PostMapping(value = "/checkGoods")
    /**
     * @description 处理商家上下架商品
     * @Param: isSell
     * @Param: id
     * @return ResponseData
     * @author Jackeys
     * @date 2021-01-30 10:08
     */
    public ResponseData checkGoods(int isSell,int id){
        return goodsService.checkGoods(isSell,id);
    }
}
